//
//  ViewController.m
//  Demo0034
//
//  Created by zTercel on 13-4-6.
//  Copyright (c) 2013年 zTercel. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	
    self.nameList   = [[NSArray alloc]initWithObjects:@"张买玉", @"李恋姐", @"林子琳", @"张国荣", @"黄阱工", @"张铁林",
                       @"徐   克", @"苍进空", @"张慧美", @"张余生", @"陈奕永",@"关之琳", @"陈德隆", @"刘青云", @"古天乐",
                       @"马伊娜", @"文   慧", @"余温华", @"陈小凌", nil];
    return;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -
#pragma mark datasource of tableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.nameList count];
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *tableViewCellIdentify  = @"tableViewCellIdentify";
    UITableViewCell *tableViewCellObject    = [tableView dequeueReusableCellWithIdentifier:tableViewCellIdentify];
    if (nil == tableViewCellObject) {
        tableViewCellObject = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault|UITableViewCellStyleValue1 reuseIdentifier:tableViewCellIdentify];
    }
    NSInteger row  = [indexPath row];
    tableViewCellObject.imageView.image = [UIImage imageNamed:@"apple.png"];
    tableViewCellObject.textLabel.text  = [self.nameList objectAtIndex:row];
    if (row > 10) {
        tableViewCellObject.detailTextLabel.text    = @"Miss zhou";
    } else {
        tableViewCellObject.detailTextLabel.text    = @"Mr yi";
    }
    
    return tableViewCellObject;
}

#pragma mark delegate of tableView
- (NSInteger)tableView:(UITableView*)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger row   = [indexPath row];
    if (row % 2 == 0)
    {
        return 0;
    }
    return 1;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger   row         = [indexPath row];
    NSString    *prompt     = [NSString stringWithFormat:@"You select item is \"%@\"", [self.nameList objectAtIndex:row]];
    UIAlertView *alertView  = [[UIAlertView alloc]initWithTitle:@"Table View"
                                                        message: prompt
                                                       delegate:self
                                              cancelButtonTitle:@"Yes, Very Good"
                                              otherButtonTitles:nil];
    [alertView show];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

@end
